#!/usr/bin/env sh
# This, weirdly, breaks nx:
# . "$(dirname -- "$0")/_/husky.sh"

# Save the list of files that are staged for commit
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)

# Run the format command
npm run format:uncommitted

# Re-add the files that were both staged and modified
for file in $STAGED_FILES; do
    if git diff --name-only --diff-filter=ACM | grep -q "^$file$"; then
        git add "$file"
    fi
done

exit 0